package com.qzy.reggie.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qzy.reggie.common.PageResult;
import com.qzy.reggie.mapper.GrfEmployeeMapper;
import com.qzy.reggie.pojo.Employee;
import com.qzy.reggie.service.GrfEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GrfEmployeeServiceImpl implements GrfEmployeeService {

    @Autowired
    private GrfEmployeeMapper grfEmployeeMapper;


    @Override
    public PageResult queryEmployeeList(Integer page, Integer pageSize, String name) {
        PageHelper.startPage(page,pageSize);

        List<Employee> employees = grfEmployeeMapper.selectList(name);

        PageInfo<Employee> pageInfo = new PageInfo<>(employees);


        return new PageResult(pageInfo.getTotal(),employees);
    }

    @Override
    public Employee queryEmployeeById(Long id) {
        if(id == null){
            return null;
        }
        Employee emp = new Employee();
        emp.setId(id);
        return grfEmployeeMapper.selectOne(emp);
    }
    @Override
    public Employee queryEmployeeByUserName(String username) {
        if (username == null || "".equals(username)){
            return null;
        }
        Employee emp = new Employee();
        emp.setUsername(username);
        return grfEmployeeMapper.selectOne(emp);
    }

    @Override
    public Integer save(Employee employee) {

        return grfEmployeeMapper.insert(employee);
    }

    @Override
    public Integer update(Employee employee) {
        return grfEmployeeMapper.update(employee);
    }

}
